import request from "@/utils/request.ts";
import type { ResponseType } from "@/types/responseTypes.d.ts";
import type { PasswordLogin, CodeLogin, Code, CodeParams } from "@/types/loginTypes.d.ts";
import type { UserInfo, UserMessage } from "@/types/userTypes.d.ts";

enum Enum {
    passwordLogin = "/login/password",
    codeLogin = "/login",
    qqLogin = "/login/thirdparty",
    sendCode = "/code",
    bindMobil = "/login/binding",
    cancelBindMobil = "/unbound",
    userMessage = "/patient/myUser",
    fetchUnReadMessage = "/patient/message/unRead/all"
}

/*密码登录接口*/
export const passwordLoginAPI = (data: PasswordLogin): Promise<ResponseType<UserInfo>> => request.post<UserInfo, ResponseType<UserInfo>, PasswordLogin>(Enum.passwordLogin, data);
/*验证码登录接口*/
export const codeLoginAPI = (data: CodeLogin): Promise<ResponseType<UserInfo>> => request.post<UserInfo, ResponseType<UserInfo>, CodeLogin>(Enum.codeLogin, data);
/*qq登录的接口*/
export const qqLoginAPI = (openId: string): Promise<ResponseType<UserInfo>> => request.post<UserInfo, ResponseType<UserInfo>>(Enum.qqLogin, { openId, source: "qq" });
/*发送验证码的接口*/
export const sendCodeAPI = (params: CodeParams): Promise<ResponseType<Code>> => request.get<Code, ResponseType<Code>>(Enum.sendCode, { params });
/*绑定手机号的接口*/
export const bindMobilAPI = (data: CodeLogin & { openId?: string }): Promise<ResponseType<UserInfo>> => request.post<UserInfo, ResponseType<UserInfo>>(Enum.bindMobil, data);
/*解绑手机号的接口*/
export const cancelBindMobilAPI = (params: string) => request.put(`${Enum.cancelBindMobil}/${params}`);
/*获取用户个人信息的接口*/
export const fetchUserMessageAPI = () => request.get<UserMessage, ResponseType<UserMessage>>(Enum.userMessage);

/*获取未读消息的接口*/
export const fetchUnReadMessageAPI = (): Promise<ResponseType<number>> => request.get<number, ResponseType<number>>(Enum.fetchUnReadMessage);
